package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo7 {
    public static void main(String[] args) throws SQLException {
        Connection conn = DBUtil.getConnection();
        Statement  st = conn.createStatement();
        String  sql = "SELECT COUNT(*) count " +
                      "FROM student s " +
                      "JOIN class c ON s.class_ id=c_id " +
                      "WHERE c.name='1年级1班' ";
        ResultSet  rs = st.executeQuery(sql);
        if (rs.next()) {
            int count = rs.getInt("count");
            System.out.println("1年级1班有"+count+"人");
        }
        conn.close();
    }
}
